<template>
	<view class="">
		<view class="content">
			<view class="search-cont">
		
				<view class="left">
					<view class="lg text-gray cuIcon-search icon-search">
		
					</view>
					<input v-model="serveName" @confirm="handleServeName" confirm-type="search" type="text" placeholder="搜索服务名称/手机号" />
				</view>
				<view class="right" @click="toPage(`/pagesPet/pages/service/saler/serve/grant`)">
					<image src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/server-k.png" mode=""></image>
					<view class="">
						发放服务卡
					</view>
				</view>
			</view>
			<view class="content-cont">
				<view v-for="(item,index) in list" :key="index" class="item">
					<view class="item-left">
						<view class="left-title text-cut">
							{{item.name}}
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/service-provider.png" mode="">
							</image>
							<view class="left-item-title">服务商：</view>
							<view class="left-item-value text-cut">{{item.pId?item.pTeamName:item.teamName}}</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/service-time.png" mode="">
							</image>
							<view class="left-item-title">服务期限：</view>
							<view class="left-item-value text-cut">{{item.startTime | countDate}} 至 {{item.endTime | countDate}}</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/grant-time.png" mode=""></image>
							<view class="left-item-title">发放时间：</view>
							<view class="left-item-value text-cut">{{item.issueTime}}</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/use-num.png" mode=""></image>
							<view class="left-item-title">状态：</view>
							<view class="left-item-value text-cut">{{item.iStatus | filterStatus}}</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/use-num.png" mode=""></image>
							<view class="left-item-title">核销次数：</view>
							<view @click="toPage(`/pagesPet/pages/service/saler/write-off-record/index?item=${encodeURIComponent(JSON.stringify(item))}`)" class="left-item-value text-cut flex align-center">{{item.useNum}}次 <i class="lg text-gray cuIcon-right"></i>
							</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/use-num.png" mode=""></image>
							<view class="left-item-title">客户名称：</view>
							<view class="left-item-value text-cut">{{item.bizName || '--'}}</view>
						</view>
						<view class="left-item">
							<image class="left-item-icon" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/use-num.png" mode=""></image>
							<view class="left-item-title">客户手机号：</view>
							<view class="left-item-value text-cut">{{item.bizTel || '--'}}</view>
						</view>
						
					</view>
					<view v-if="!item.iStatus && item.type=='USER'" class="item-bottom">
						<view class="item-bottom-btn" @click="cancellation(item)" style="background: #FFF4F4;color: var(--primaryBg);">
							作废
						</view>
						<view class="item-bottom-btn" @click="useClick(item)">
							核销
						</view>
					</view>
				</view>
				<view class="none">
					没有更多了～
				</view>
			</view>
		</view>
				
		<showModal ref="showModal"></showModal>
		<use ref="use"></use>		
	</view>
</template>

<script>
	import {
		checkService,
		cancelService
	} from "@/api/pet/service/saler.js"
	import showModal from "@/components/show-modal1"
	import use from "./use.vue"
	
	export default {
		components: {
			showModal,
			use
		},
		props:{
			serveName:String,
			list:Array,
			
		},
		data(){
			return {
				
			}
		},
		filters:{
			countDate(val){
				return val.slice(0,10)
			},
			filterStatus(val){
				if(!val){
					return '使用中'
				}
				if(val == 1){
					return '服务下线'
				}
				if(val == 2){
					return '已作废'
				}
				if(val == 3){
					return '已使用'
				}
				if(val == 4){
					return '已结束'
				}
			}
		},
		methods:{
			toPage(url){
				uni.navigateTo({
					url:url
				})
			},
			useClick(item){
				this.$refs.use.open({
					item:item,
					success:(data)=>{
						checkService(data).then(res=>{
							uni.showToast({
								title:'操作成功',
								icon:'none'
							})
							this.$parent.init()
						})
					}
				})
			},
			cancellation(item){
				this.$refs.showModal.open({
					// title:"作废提醒",
					content:"确定将此次发放的服务作废吗？",
					success:(type)=>{
						cancelService({
							issueId:item.issueId
						}).then(res=>{
							uni.showToast({
								title:'操作成功',
								icon:'none'
							})
							this.$parent.init()
						})
					}
				})
			},
			handleServeName(e){
				console.log(e)
				this.$emit('input',e.detail.value)
			}
		}
	}
</script>

<style scoped lang="scss">
	
	.content {
		flex: 1;
		position: relative;
		width: 100%;
		background: #F8F8F8;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		box-sizing: border-box;
	
		top: -28rpx;
	
		.content-cont {
			padding: 16rpx;
		}
	
		.item {
			width: 100%;
			background: #FFFFFF;
			border-radius: 12rpx;
			margin-bottom: 16rpx;
			padding: 22rpx 24rpx;
			box-sizing: border-box;
	
			.item-left {
				flex: 1;
	
				.left-title {
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 32rpx;
					color: var(--h1Color);
					line-height: 45rpx;
					margin-bottom: 24rpx;
				}
	
				.left-item {
					width: 100%;
					display: flex;
					align-items: center;
					overflow: hidden;
					margin-bottom: 12rpx;
	
					&:last-child {
						margin-bottom: 0;
					}
	
					view {
						// font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: var(--h2Color);
						line-height: 40rpx;
					}
	
					.left-item-icon {
						margin-right: 12rpx;
						width: 26rpx;
						height: 26rpx;
					}
	
					.left-item-title {
						width: 170rpx;
	
					}
	
					.left-item-value {
						flex: 1;
					}
				}
			}
	
			.item-bottom {
				display: flex;
				align-items: center;
				justify-content: flex-end;
	
				.item-bottom-btn {
					margin-left: 12rpx;
					width: 142rpx;
					background: var(--primaryBg);
					border-radius: 12rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: var(--btnColor);
					line-height: 64rpx;
					text-align: center;
				}
			}
		}
	
		.none {
			width: 100%;
			text-align: center;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: var(--h4Color);
			line-height: 33rpx;
			margin-top: 40rpx;
		}
	}
	.search-cont {
		width: 100%;
		height: 108rpx;
		background: #FFFFFF;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 16rpx 24rpx;
	
		.left {
			position: relative;
	
			.icon-search {
				position: absolute;
				left: 15rpx;
				top: 50%;
				transform: translateY(-50%);
			}
	
			input {
				padding: 0 30rpx 0 45rpx;
				width: 574rpx;
				height: 76rpx;
				background: #F8F8F8;
				border-radius: 40rpx;
			}
		}
	
		.right {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
	
			image {
				width: 44rpx;
				height: 44rpx;
			}
	
			view {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 20rpx;
				color: var(--h1Color);
				line-height: 28rpx;
				text-align: left;
				font-style: normal;
			}
		}
	}
	
</style>